package com.suli.account.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.suli.account.entity.UserTicket;
import com.suli.account.enums.TicketStatus;
import com.suli.account.mapper.ScenicTicketMapper;
import com.suli.account.mapper.UserTicketMapper;
import com.suli.account.service.UserTicketService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SuLi
 * @since 2022-04-14
 */
@Service
@Transactional
public class UserTicketServiceImpl extends ServiceImpl<UserTicketMapper, UserTicket> implements UserTicketService {

    @Autowired
    UserTicketMapper ticketMapper;
    @Autowired
    ScenicTicketMapper scenicTicketMapper;
    @Override
    public Map<String, Object> getCountByType(String ticketType) {
        QueryWrapper<UserTicket> queryWrapper=new QueryWrapper<>();
        queryWrapper.eq("ticket_status", TicketStatus.valueOf(ticketType));
        Long aLong = ticketMapper.selectCount(queryWrapper);
        Map<String,Object> map=new HashMap<>();
        map.put("AllCount", aLong);
        return map;
    }

    @Override
    public Map<String, Object> getSaleByTime(Date startTime, Date endTime) {
        QueryWrapper<UserTicket> queryWrapper=new QueryWrapper<>();
        queryWrapper.between("ticket_buy_time", startTime, endTime);
        Long aLong = ticketMapper.selectCount(queryWrapper);
        Map<String,Object> map=new HashMap<>();
        map.put("AllCount", aLong);
        return map;
    }

    @Override
    public Map<String, Object> getSaleInTime(Date startTime, Date endTime) {
        QueryWrapper<UserTicket> queryWrapper=new QueryWrapper<>();
        queryWrapper.select("ticket_price").between("ticket_buy_time", startTime, endTime);
        List<UserTicket> userTickets = ticketMapper.selectList(queryWrapper);
         BigDecimal bigDecimal = new BigDecimal(0);
        for (UserTicket userTicket : userTickets) {
            bigDecimal = bigDecimal.add(userTicket.getTicketPrice());
        }
        Map<String, Object> map=new HashMap<>();
        map.put("AllCount", bigDecimal);
        return map;
    }
}
